package com.example.myapplication.ui.feedback

import android.os.Bundle
import android.text.Editable
import android.text.TextWatcher
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import com.alibaba.android.arouter.facade.annotation.Route
import com.example.myapplication.databinding.ActivityFeedbackBinding

@Route(path = "/feedback/activity")
class FeedbackActivity : AppCompatActivity() {
    private lateinit var binding: ActivityFeedbackBinding
    private var mSelectableItem: SelectableItem = SelectableItem("功能建议", true)

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        binding = ActivityFeedbackBinding.inflate(layoutInflater)
        setContentView(binding.root)
        supportActionBar?.hide()
        binding.apply {
            ivBack.setOnClickListener {
                finish()
            }
            tvCommit.setOnClickListener {
                Toast.makeText(this@FeedbackActivity, "提交成功", Toast.LENGTH_LONG).show()
                finish()
            }
            rvTag.adapter = FeedbackTagsAdapter(
                arrayListOf(
                    mSelectableItem,
                    SelectableItem("日期错乱问题", false),
                    SelectableItem("备忘录问题", false),
                    SelectableItem("老黄历问题", false),
                    SelectableItem("其他", false)
                ), onTagSelect = { selectableItem ->
                    mSelectableItem = selectableItem
                })

            etContent.addTextChangedListener(object : TextWatcher {
                override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {
                    // 文本变化前的回调（一般无需处理）
                }

                override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {
                    // 文本变化时的回调（可实时更新UI）
                    val currentLength = s?.length ?: 0
                    tvTextLimit.text = "$currentLength/600"
                }

                override fun afterTextChanged(s: Editable?) {
                    // 文本变化后的回调（适合校验或触发业务逻辑）
                    if ((s?.length ?: 0) > 600) {
                        Toast.makeText(this@FeedbackActivity, "字数超过限制", Toast.LENGTH_LONG).show()
                    }
                }
            })
        }
    }
}